<!--用户管理页-->
<template>
  <div style="height: 6vh;background-color:#fff;padding:10px 20px;">
    <span style="line-height:60px;font-size:20px;float: left">投递过程跟踪</span>
<!--    <el-button @click="dialogVisible=true" type="primary" color="#5B63B7"-->
<!--               style="float:right;margin-top:13px;">新建投递简历</el-button>-->
  </div>
  <!-- 新增简历弹窗 -->
  <el-dialog :title="dialogTitle" style="width:600px;padding:40px;" v-model="dialogVisible" :before-close="handleClose">
    <el-form label-width="50px" label-position="top">
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="公司名称">
            <el-input placeholder="请输入公司名称" v-model="saveDeliveryForm.corporateName" :disabled="saveDeliveryForm.corporateName!=null"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="招聘职位">
            <el-input placeholder="请输入招聘职位" v-model="saveDeliveryForm.recruitmentPosition"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="招聘人数">
            <el-input placeholder="请输入招聘人数" v-model="saveDeliveryForm.numberOfRecruits"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="职位待遇">
            <el-input placeholder="请输入职位待遇" v-model="saveDeliveryForm.positionTreatment"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
<!--      <el-row :gutter="30">-->
<!--        <el-col :span="12">-->
<!--          <el-form-item label="发布人">-->
<!--            <el-input placeholder="请输入发布人" v-model="saveDeliveryForm.publisherFullName" :disabled="saveDeliveryForm.publisherFullName!=null"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col :span="12">-->
<!--          <el-form-item label="应聘人">-->
<!--            <el-input placeholder="请输入应聘人" v-model="saveDeliveryForm.candidateFullName" :disabled="saveDeliveryForm.candidateFullName!=null"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--      </el-row>-->
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="联系电话">
            <el-input placeholder="请输入联系电话" v-model="saveDeliveryForm.contactNumber"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="招聘状态">
            <el-input placeholder="招聘状态" v-model="saveDeliveryForm.resumeStatus"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="回复信息">
            <el-input placeholder="请输入回复信息" v-model="saveDeliveryForm.replyMessage"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button  @click="handleClose()" style="color: #5B63B7;" class="custom-hover-color">取消</el-button>
      <el-button type="primary" color="#5B63B7" @click="saveDelivery()">保存</el-button>
    </template>
  </el-dialog>

  <!-- 投递查询卡片 -->
  <el-card style="margin:20px;height: 70px;">
    <el-form :inline="true">
      <el-form-item label="公司名称" style="float: left">
        <el-input placeholder="输入公司名称" style="width:220px;"
                  v-model="searchDeliveryForm.corporateName" @keydown.enter="loadDelivery"></el-input>
      </el-form-item>
      <el-form-item label="招聘职位" style="float: left">
        <el-input placeholder="输入招聘职位" style="width:220px;"
                  v-model="searchDeliveryForm.recruitmentPosition" @keydown.enter="loadDelivery"></el-input>
      </el-form-item>
<!--      <el-form-item label="发布人" style="float: left">-->
<!--        <el-input placeholder="输入发布人" style="width:220px;"-->
<!--                  v-model="searchDeliveryForm.publisher" @keydown.enter="loadDelivery"></el-input>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="应聘人">-->
<!--        <el-input placeholder="输入应聘人" style="width:220px;"-->
<!--                  v-model="searchDeliveryForm.candidate" @keydown.enter="loadDelivery"></el-input>-->
<!--      </el-form-item>-->
      <el-form-item label="招聘状态" style="float: left">
        <el-input placeholder="输入招聘状态" style="width:220px;"
                  v-model="searchDeliveryForm.resumeStatus" @keydown.enter="loadDelivery"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetSearch">重置</el-button>
        <el-button type="primary" @click="loadDelivery" color="#5B63B7">查询</el-button>
      </el-form-item>
    </el-form>
  </el-card>
  <!-- 用户信息表格 -->
  <el-card style="margin:20px;">
    <el-table :data="DeliveryArr">
      <el-table-column type="index" label="编号" width="80" align="center"/>
      <el-table-column prop="corporateName" label="公司名称" align="center"/>
      <el-table-column prop="recruitmentPosition" label="招聘职位" align="center"/>
      <el-table-column prop="numberOfRecruits" label="招聘人数" align="center"/>
      <el-table-column prop="positionTreatment" label="职位待遇" align="center"/>
<!--      <el-table-column prop="publisherFullName" label="发布人" align="center"/>-->
<!--      <el-table-column prop="candidateFullName" label="应聘人" align="center"/>-->
      <el-table-column prop="contactNumber" label="联系电话" align="center"/>
<!--      <el-table-column prop="resumeFile" label="简历文件" align="center"/>-->
      <el-table-column prop="resumeStatus" label="招聘状态" align="center"/>
      <el-table-column prop="replyMessage" label="回复信息" align="center"/>
<!--      <el-table-column prop="recommend" label="智能推荐" align="center">-->
<!--      <template #default="scope">-->
<!--        <el-switch @change="changeStatus(scope.row.id,scope.row.recommend)" active-value="1" inactive-value="0" v-model="scope.row.recommend"></el-switch>-->
<!--      </template>-->
<!--      </el-table-column>-->
      <el-table-column prop="createTime" label="创建时间" align="center"/>
      <el-table-column prop="updateTime" label="更新时间" align="center"/>
<!--      <el-table-column label="操作" align="center">-->
<!--        <template #default="scope">-->
<!--          <el-button link type="primary" size="small" @click="editDelivery(scope.row.id)" style="color:#5B63B7">编辑</el-button>-->
<!--          <el-button link type="primary" size="small" @click="deleteDelivery(scope.row.id)" style="color:#5B63B7">删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
  </el-card>
</template>

<script setup>
import {onMounted, ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";
import qs from "qs";

//控制新增用户弹窗是否显示
const dialogVisible = ref(false);
//定义变量控制dialog的标题
const dialogTitle = ref('新建投递简历');
//准备对象用来收集新增/修改投递简历的表单信息
const saveDeliveryForm = ref({
  id:'',
  corporateName: '',
  recruitmentPosition:'',
  numberOfRecruits:'',
  positionTreatment:'',
  resumeInformationId: '',
  recruitmentInformationId:'',
  contactNumber:'',
  resumeStatus:'',
  replyMessage:'',
  createTime:'',
  updateTime:'',
  resumeFile:'',
  recommend:'',
  seekerId:'',
  hrId:''
});
// //新增员工
const saveDelivery = () => {
  let data = JSON.stringify(saveDeliveryForm.value);
  console.log(data);
  axios.post(BASE_URL+'/v1/delivery/save',data, {
    headers: {
      'Content-Type': 'application/json' // 明确指定请求体类型为 JSON
    }
  }).then((response) => {
    if (response.data.code === 2000) {
      ElMessage.success('保存成功!');
      dialogVisible.value = false;//关闭弹窗
      saveDeliveryForm.value={};//清空输入的数据,防止新增成功后打开弹窗还是之前的数据
      loadDelivery();//加载用户列表方法
    } else {
      ElMessage.error(response.data.msg);
    }
  })
}

// //实现取消按钮的功能
const handleClose = ()=>{
  if(confirm('是否关闭本窗口?')){
    //用户确认关闭后,将审批弹窗与确认驳回弹窗一起关掉
    dialogVisible.value = false;
    //取消时把填的数据都清空，表单回复到初始状态
    saveDeliveryForm.value={};
  }
}

//定义数组用来装用户列表信息
const DeliveryArr = ref([]);
//定义对象保存查询条件
const searchDeliveryForm = ref({corporateName: '', recruitmentPosition: '',resumeStatus:''});
const loadDelivery = () => {
  //如果传入了查询条件，则根据条件查询，没有条件，默认查询所有员工信息
  let data = qs.stringify(searchDeliveryForm.value);
  console.log(data);
  axios.get(BASE_URL+'/v1/delivery/select?'+data).then((response) => {
    if (response.data.code === 2000) {
      DeliveryArr.value = response.data.data;
      console.log(DeliveryArr.value);
    } else {
      ElMessage.error(response.data.msg);
    }
  })
}

//页面一加载立即调用
onMounted(() => {
  searchDeliveryForm.value={};
  loadDelivery();//加载员工列表
})

//重置用户搜索信息
const resetSearch = ()=>{
  searchDeliveryForm.value={};
  loadDelivery();
}


//编辑员工
const editDelivery = (id) =>{
  console.log(id);
  //修改弹窗标题并打开弹窗
  dialogTitle.value = '编辑投递信息';
  dialogVisible.value = true;
  //根据id查询要修改的当前员工的信息
  axios.get(BASE_URL+'/v1/delivery/select?id='+id).then((response) => {
    if (response.data.code === 2000) {
      //若请求成功，赋值给saveUserForm，因为后端返回的是list，所以这里要data[0]
      saveDeliveryForm.value = response.data.data[0];
      console.log(response.data.data)
    } else {
      ElMessage.error(response.data.msg);
    }
  })
}

//删除用户
const deleteDelivery = (id)=>{
  console.log(id);
  if(confirm('您确认要删除此投递记录吗?')){
    axios.post(BASE_URL+'/v1/delivery/delete/'+id).then((response) => {
      if (response.data.code === 2000) {
        ElMessage.success('删除成功!');
        loadDelivery();
      } else {
        ElMessage.error(response.data.msg);
      }
    })
  }
}

//修改智能推荐
const changeStatus = (id,recommend) => {
  axios.post(BASE_URL+'/v1/delivery/update/'+id+'/'+recommend).then((response) => {
    if (response.data.code === 2000) {
      //ElMessage.success('修改成功!');
    } else {
      ElMessage.error(response.data.msg);
    }
  })
}
</script>

<style scoped>
.custom-hover-color:hover {
  color: #5B63B7; /* 悬停时的文本颜色 */
  background-color: #f5f5f5;
  border-color: #cccccc;
}
/*出生日期*/
.demo-datetime-picker {
  display: flex;
  width: 100%;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
  justify-content: space-around;
  align-items: stretch;
}
.demo-datetime-picker .block {
  padding: 30px 0;
  text-align: center;
}
</style>